﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StudentWeb.DAL;
using StudentWeb.Model;
using StudentWeb.Common;

namespace StudentWeb.BLL
{
    public class XhEventBO
    {
        #region 活动信息 分页列表
        /// <summary>
        /// 图书信息 分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="wc"></param>
        /// <returns></returns>
        public IResult GetXhEventList(int pageIndex, int pageSize, string wc = null)
        {
            var list = new XhEventDataDAO().GetList(pageIndex, pageSize, wc);
            return new DataResult<PagedList<XhEventData>>(list);
        }
        #endregion
        #region 活动信息 单条记录
        /// <summary>
        /// 图书信息 单条记录
        /// </summary>
        /// <param name="XhEventID"></param>
        /// <returns></returns>
        public IResult GetXhEventInfo(int XhEventID)
        {
            var res = new XhEventDataDAO().GetInfo(XhEventID);
            return new DataResult<XhEventData>(res);
        }
        #endregion
        #region 活动信息 保存
        public bool SaveXhEventInfo(dynamic data, int userid)
        {
            int xheventID = data.XhEventID ?? 0;
            var result = 0;
            if (xheventID > 0)
            {
                var record = new XhEventDataDAO().GetInfo(xheventID);
                //XhEventID

                //CourseState课程状态
                record.XhEventName = data.XhEventName;//活动名称

                //record.XhReservedDuration = data.XhReservedDuration;//开设学期

                record.XhLocation = data.XhLocation;//活动地点
                
                record.XhEventDate = DateTime.Now;



                result = new XhEventDataDAO().Update(record);
            }
            else if (xheventID == 0)
            {
                var xhevent = new XhEventData()
                {
                    //CourseDataID=自动
                    //CourseDataID=自动



                    XhEventName = data.XhEventName,


                    XhLocation = data.XhLocation,



                    XhEventDate = DateTime.Now,


                };
                result = new XhEventDataDAO().Insert(xhevent);
            }
            return result > 0;
        }
        #endregion
        #region 活动信息 删除
        public IResult DeleteEventInfo(int XhEventID)
        {
            var res = new XhEventDataDAO().Delete(XhEventID);
            if (res > 0)
            {
                return new Result(ResultCode.Success, "删除成功");
            }
            else
            {
                return new Result(ResultCode.Fail, "删除失败");
            }
        }
        #endregion
        
    }
}
